home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Tools - Objects / MacApp / MacApp 2.0 CD Release / MacApp 2.0 (Many Libraries) / Examples / CPlusExamples / Nothing / Nothing.cp
Encoding:
Text File  |  1990-03-27  |  4.6 KB  |  156 lines  |  [TEXT/MPS ]

  1. // Nothing.cp
  2. // Copyright © 1986-1990 by Apple Computer, Inc. All rights reserved.
  3.  
  4. /*
  5.     This is a very small sample application which can save files on disk and can
  6.     print.
  7.  
  8.     The application's windows each contain the word 'MacApp', in large type, and
  9.     are framed by a large gray border.
  10.  
  11.     Documents can be saved on disk and later reopened, but the only
  12.     document-specific information saved in the disk file is the Print information,
  13.     which means that if you set print specifications using the Page Setup dialog
  14.     for a document, and then save the document (using Save As or Save a Copy),
  15.     those specifications are saved on disk, and when you reopen the document
  16.     you will find those same print specifications holding for the document.
  17.  
  18.  
  19.     All applications that create views procedurally need to reimplement at least three
  20.     methods:
  21.  
  22.        TApplication.DoMakeDocument    --    Launches the appropriate type of Document object
  23.        TDocument.DoMakeViews        --    Launches the appropriate type of View and window objects
  24.        TView.Draw                    --    Draws the contents of a view
  25.  
  26.     This application, however, consists of the reimplementation of only one method -
  27.     TView.Draw.  This is possible since the view is created from templates;  MacApp
  28.     supplies the default 'view' resource.  So in a sense this application is the smallest
  29.     possible MacApp application.
  30. */
  31.  
  32. //  {$MC68020-}                                                // The main program must be universal code
  33. //  {$MC68881-}
  34.  
  35. //-------------------------------------------------------------------------------------
  36. // INCLUDES
  37.  
  38.         // • MacApp
  39. #include <UMacApp.h>
  40.         // • Building Blocks
  41. #include <UPrinting.h>
  42.         // • Implementation Use
  43. #include <Fonts.h>
  44.  
  45. //-------------------------------------------------------------------------------------
  46. // CONSTANTS
  47.  
  48. const OSType kSignature = 'SS01';    // Application signature
  49. const OSType kFileType = 'SF01';    // File-type code used for document files created by this application
  50.  
  51. //-------------------------------------------------------------------------------------
  52. // TYPES
  53.  
  54. class TNothingApplication : public TApplication {
  55. public:
  56.     // Initializes the application and globals. 
  57.     virtual pascal void INothingApplication(OSType itsMainFileType);
  58. };
  59.  
  60. class TDefaultView : public TView {
  61. public:
  62.     // Draws the view seen in the window. Every nonblank view MUST override this method. 
  63.     virtual pascal void Draw(Rect *area);
  64. };
  65.  
  66. //-------------------------------------------------------------------------------------
  67.  
  68. pascal void TNothingApplication::INothingApplication(OSType itsMainFileType)
  69. {
  70.     IApplication(itsMainFileType);
  71.  
  72.     // So my view will be substituted when MacApp® creates the "default view"
  73.     RegisterStdType("\pTDefaultView", 'dflt');
  74.     
  75.     // So the linker doesn't dead strip class info 
  76.     if (gDeadStripSuppression)
  77.       {
  78.         TDefaultView *aDfltView;
  79.         aDfltView = new TDefaultView;
  80.       }
  81. }
  82.  
  83. // ---------------------------------------------------------------------------------------
  84.  
  85. // NOTE: we don't define a name for the argument here, so CFront won't complain about
  86. // the argument being unused!
  87. pascal void TDefaultView::Draw(Rect *)
  88. {
  89.     Rect itsQDExtent;
  90.  
  91.     PenNormal();
  92.     PenSize(10, 10);
  93.     PenPat(qd.dkGray);
  94.  
  95.     // We know its extent always fits in QuickDraw coordinates.
  96.     GetQDExtent(&itsQDExtent);
  97.     // Draw a dark gray frame
  98.     FrameRect(&itsQDExtent); 
  99.  
  100.     // Set font and size for subsequent display in the window
  101.     TextFont(applFont);
  102.     TextSize(72);
  103.  
  104.     MoveTo(45, 90);
  105.     // Draw the word 'MacApp®' in large type.
  106.     DrawString("\pMacApp®");
  107.     // Restore the pen state.
  108.     PenNormal();
  109. }
  110.  
  111. // ---------------------------------------------------------------------------------------
  112. // T H E   M A I N    P R O G R A M
  113.  
  114. // GLOBALS
  115. TNothingApplication *gNothingApplication;        // The application object 
  116.  
  117. void main()
  118. {
  119.     // Essential toolbox and utilities initialization
  120.     InitToolBox();
  121.  
  122.     // Make sure we can run 
  123.     if (ValidateConfiguration(&gConfiguration))
  124.       {
  125.         // We made it! Continue with remainder of initialization 
  126.  
  127.         // Initialize MacApp; 8 calls to MoreMasters
  128.         InitUMacApp(8);
  129.  
  130.         // ------------------------------------------------------
  131.         // If you are going to use streams for debugging IO then:
  132.         // #include <stdio.h>
  133.         // #include <iostream.h>
  134.         // and execute the following line since MacApp's debug output is essentialy "printf"s
  135.  
  136.         // cout.sync_with_stdio();
  137.  
  138.         InitUPrinting();
  139.  
  140.         // Allocate a new TNothingApplication object, and check for errors
  141.         gNothingApplication = new TNothingApplication;
  142.         FailNIL(gNothingApplication);
  143.         // Initialize the application object
  144.         gNothingApplication->INothingApplication(kFileType);
  145.  
  146.         // Run the application. When it's done, exit.
  147.  
  148.         gNothingApplication->Run();
  149.       }
  150.     else
  151.         {
  152.         StdAlert(phUnsupportedConfiguration);
  153.         }
  154.  
  155. }
  156.